package com.zzx.controller;

import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonFormat.Value;
import com.zzx.model.User;


@Controller
@RequestMapping("/hello")
public class HelloController {
										//?name=张三&age=10aa 参数的过滤
//	@RequestMapping(value="/{addr}/info",params= {"name","age!=10"},method=RequestMethod.GET,headers= {"User-Agent"})//   /hello/info
	@GetMapping(value="/{addr}/info",headers= {"User-Agent"})
	@ResponseBody
	public String info(@PathVariable("addr") String abc,
							@RequestHeader("User-Agent") String ua) {
		
		return "<h1><a href='http://localhost:8080/hello'>哈哈</a></h1>"
				+ "<select id=\"province\">\r\n" + 
				"     <option>---请选择---</option>\r\n" + 
				"</select>\r\n" + 
				"<select id=\"city\">\r\n" + 
				"    <option>---请选择---</option>\r\n" + 
				"</select>"+abc+"</br>"+ua;
	}
	
	@GetMapping("testcook")
	@ResponseBody
	public String cook(HttpServletRequest request) {
		Cookie[] cookies = request.getCookies();
		String  cv="";
		for (Cookie cookie : cookies) {
			if(cookie.equals("zzx")) {
				cv=cookie.getValue();
			}
			
		}
		return cv;
	}
	
	@GetMapping("testcook2")
	public @ResponseBody String cook2(@CookieValue("zzx") String sv) {
		return sv;
	}
	
	@GetMapping("login")
	public @ResponseBody Object login(@Valid User user,Map<String, Object> map) {
		user.setName("哈哈");
		map.put("user", user);
		return user;
		//return "Users";
	}
	
}
